{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Openbb-agents\n",
    "This is a short example notebook to demonstrate some of the features of `openbb-agents`, and to get you up and running as quickly as possible."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Set-up\n",
    "We'll be fetching our data provider API keys using OpenBB Platform's backend for this example (it's free to sign up!).\n",
    "\n",
    "You are also free to set-up your [API keys](https://docs.openbb.co/sdk/usage/api-keys) locally, or to rely only on `yfinance`\n",
    "as a provider for data provider (although keep in mind that certain functions\n",
    "will not be available as a result)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "OPENBB_PAT = os.environ.get('OPENBB_PAT')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Basic Querying"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-06-03 10:44:55,082 - INFO - openbb_agents.agent - Using all available OpenBB tools with providers: ['yfinance', 'fmp']\n",
      "2024-06-03 10:44:55,083 - INFO - openbb_agents.tools - Building OpenBB tool vector index...\n",
      "2024-06-03 10:45:07,729 - INFO - openbb_agents.agent - Generating subquestions for user query: What is the current stock price of TSLA?\n",
      "2024-06-03 10:45:08,918 - INFO - openbb_agents.agent - Generated subquestions: [SubQuestion(id=1, question='What is the current stock price of TSLA?', depends_on=None)]\n",
      "2024-06-03 10:45:08,919 - INFO - openbb_agents.agent - Answering subquestion: id=1 question='What is the current stock price of TSLA?' depends_on=None\n",
      "2024-06-03 10:45:08,920 - INFO - openbb_agents.agent - Attempting to select tools for: {'What is the current stock price of TSLA?'}\n",
      "2024-06-03 10:45:09,662 - INFO - openbb_agents.chains - Searching tool index for: stock price\n",
      "2024-06-03 10:45:11,093 - INFO - openbb_agents.agent - Retrieved tool(s): ['quote', 'price_performance', 'historical']\n",
      "2024-06-03 10:45:11,094 - INFO - openbb_agents.agent - Answering subquestion: What is the current stock price of TSLA?\n",
      "2024-06-03 10:45:12,176 - INFO - openbb_agents.chains - Function call: quote({'symbol': 'TSLA', 'provider': 'fmp'})\n",
      "2024-06-03 10:45:16,589 - INFO - openbb_agents.agent - Answered subquestion: - The current stock price of Tesla, Inc. (TSLA) is $178.08.\n",
      "- This data was last updated on May 31, 2024, at 20:00:03 UTC.\n",
      "- The stock opened at $178.42, reached a high of $180.32, and a low of $173.8201 on the same day.\n",
      "- The previous closing price was $178.79, indicating a slight decrease of $0.71 or approximately -0.40%.\n",
      "- The current stock price of Tesla, Inc. (TSLA) is $178.08.\n",
      "- This data was last updated on May 31, 2024, at 20:00:03 UTC.\n",
      "- The stock opened at $178.42, reached a high of $180.32, and a low of $173.8201 on the same day.\n",
      "- The previous closing price was $178.79, indicating a slight decrease of $0.71 or approximately -0.40%.\n"
     ]
    }
   ],
   "source": [
    "from openbb_agents.agent import openbb_agent\n",
    "\n",
    "result = openbb_agent(\"What is the current stock price of TSLA?\", openbb_pat=OPENBB_PAT)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- The current stock price of Apple Inc. (AAPL) is $192.25.\n",
      "- This data was last updated on May 31, 2024, at 20:00:03 UTC.\n",
      "- The stock opened at $191.44, reached a high of $192.57, and a low of $189.91 on the same day.\n",
      "- The previous closing price was $191.29.\n",
      "- The stock has a year high of $199.62 and a year low of $164.08.\n",
      "- The average volume over the last 50 days is 62,563,592 shares.\n",
      "- The market capitalization of Apple Inc. is approximately $2.95 trillion.\n"
     ]
    }
   ],
   "source": [
    "# You can turn off verbose output to only receive the answer.\n",
    "result = openbb_agent(\"What is the current stock price of AAPL?\", verbose=False)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Use only specific OpenBB Platform tools\n",
    "You don't have to rely on the entire suite of OpenBB tools. In certain\n",
    "use-cases, it makes sense to limit the agent to only a small subset of the\n",
    "tools."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>period_ending</th>\n",
       "      <th>fiscal_period</th>\n",
       "      <th>fiscal_year</th>\n",
       "      <th>filing_date</th>\n",
       "      <th>accepted_date</th>\n",
       "      <th>reported_currency</th>\n",
       "      <th>revenue</th>\n",
       "      <th>cost_of_revenue</th>\n",
       "      <th>gross_profit</th>\n",
       "      <th>gross_profit_margin</th>\n",
       "      <th>...</th>\n",
       "      <th>pre_tax_income_margin</th>\n",
       "      <th>income_tax_expense</th>\n",
       "      <th>consolidated_net_income</th>\n",
       "      <th>net_income_margin</th>\n",
       "      <th>basic_earnings_per_share</th>\n",
       "      <th>diluted_earnings_per_share</th>\n",
       "      <th>weighted_average_basic_shares_outstanding</th>\n",
       "      <th>weighted_average_diluted_shares_outstanding</th>\n",
       "      <th>link</th>\n",
       "      <th>final_link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2023-06-30</td>\n",
       "      <td>FY</td>\n",
       "      <td>2023</td>\n",
       "      <td>2023-07-27</td>\n",
       "      <td>2023-07-27 16:01:56</td>\n",
       "      <td>USD</td>\n",
       "      <td>2.119150e+11</td>\n",
       "      <td>6.586300e+10</td>\n",
       "      <td>1.460520e+11</td>\n",
       "      <td>0.689201</td>\n",
       "      <td>...</td>\n",
       "      <td>0.421447</td>\n",
       "      <td>1.695000e+10</td>\n",
       "      <td>7.236100e+10</td>\n",
       "      <td>0.341462</td>\n",
       "      <td>9.72</td>\n",
       "      <td>9.68</td>\n",
       "      <td>7.446000e+09</td>\n",
       "      <td>7.472000e+09</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-06-30</td>\n",
       "      <td>FY</td>\n",
       "      <td>2022</td>\n",
       "      <td>2022-07-28</td>\n",
       "      <td>2022-07-28 16:06:19</td>\n",
       "      <td>USD</td>\n",
       "      <td>1.982700e+11</td>\n",
       "      <td>6.265000e+10</td>\n",
       "      <td>1.356200e+11</td>\n",
       "      <td>0.684017</td>\n",
       "      <td>...</td>\n",
       "      <td>0.422232</td>\n",
       "      <td>1.097800e+10</td>\n",
       "      <td>7.273800e+10</td>\n",
       "      <td>0.366863</td>\n",
       "      <td>9.70</td>\n",
       "      <td>9.65</td>\n",
       "      <td>7.496000e+09</td>\n",
       "      <td>7.540000e+09</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>FY</td>\n",
       "      <td>2021</td>\n",
       "      <td>2021-07-29</td>\n",
       "      <td>2021-07-29 16:21:55</td>\n",
       "      <td>USD</td>\n",
       "      <td>1.680880e+11</td>\n",
       "      <td>5.223200e+10</td>\n",
       "      <td>1.158560e+11</td>\n",
       "      <td>0.689258</td>\n",
       "      <td>...</td>\n",
       "      <td>0.423005</td>\n",
       "      <td>9.831000e+09</td>\n",
       "      <td>6.127100e+10</td>\n",
       "      <td>0.364517</td>\n",
       "      <td>8.12</td>\n",
       "      <td>8.05</td>\n",
       "      <td>7.547000e+09</td>\n",
       "      <td>7.608000e+09</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-06-30</td>\n",
       "      <td>FY</td>\n",
       "      <td>2020</td>\n",
       "      <td>2020-07-30</td>\n",
       "      <td>2020-07-30 20:44:46</td>\n",
       "      <td>USD</td>\n",
       "      <td>1.430150e+11</td>\n",
       "      <td>4.607800e+10</td>\n",
       "      <td>9.693700e+10</td>\n",
       "      <td>0.677810</td>\n",
       "      <td>...</td>\n",
       "      <td>0.370842</td>\n",
       "      <td>8.755000e+09</td>\n",
       "      <td>4.428100e+10</td>\n",
       "      <td>0.309625</td>\n",
       "      <td>5.82</td>\n",
       "      <td>5.76</td>\n",
       "      <td>7.610000e+09</td>\n",
       "      <td>7.683000e+09</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-06-30</td>\n",
       "      <td>FY</td>\n",
       "      <td>2019</td>\n",
       "      <td>2019-08-01</td>\n",
       "      <td>2019-08-01 16:09:55</td>\n",
       "      <td>USD</td>\n",
       "      <td>1.258430e+11</td>\n",
       "      <td>4.291000e+10</td>\n",
       "      <td>8.293300e+10</td>\n",
       "      <td>0.659020</td>\n",
       "      <td>...</td>\n",
       "      <td>0.347163</td>\n",
       "      <td>4.448000e+09</td>\n",
       "      <td>3.924000e+10</td>\n",
       "      <td>0.311817</td>\n",
       "      <td>5.11</td>\n",
       "      <td>5.06</td>\n",
       "      <td>7.673000e+09</td>\n",
       "      <td>7.753000e+09</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "      <td>https://www.sec.gov/Archives/edgar/data/789019...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  period_ending fiscal_period  fiscal_year filing_date       accepted_date  \\\n",
       "0    2023-06-30            FY         2023  2023-07-27 2023-07-27 16:01:56   \n",
       "1    2022-06-30            FY         2022  2022-07-28 2022-07-28 16:06:19   \n",
       "2    2021-06-30            FY         2021  2021-07-29 2021-07-29 16:21:55   \n",
       "3    2020-06-30            FY         2020  2020-07-30 2020-07-30 20:44:46   \n",
       "4    2019-06-30            FY         2019  2019-08-01 2019-08-01 16:09:55   \n",
       "\n",
       "  reported_currency       revenue  cost_of_revenue  gross_profit  \\\n",
       "0               USD  2.119150e+11     6.586300e+10  1.460520e+11   \n",
       "1               USD  1.982700e+11     6.265000e+10  1.356200e+11   \n",
       "2               USD  1.680880e+11     5.223200e+10  1.158560e+11   \n",
       "3               USD  1.430150e+11     4.607800e+10  9.693700e+10   \n",
       "4               USD  1.258430e+11     4.291000e+10  8.293300e+10   \n",
       "\n",
       "   gross_profit_margin  ...  pre_tax_income_margin  income_tax_expense  \\\n",
       "0             0.689201  ...               0.421447        1.695000e+10   \n",
       "1             0.684017  ...               0.422232        1.097800e+10   \n",
       "2             0.689258  ...               0.423005        9.831000e+09   \n",
       "3             0.677810  ...               0.370842        8.755000e+09   \n",
       "4             0.659020  ...               0.347163        4.448000e+09   \n",
       "\n",
       "   consolidated_net_income  net_income_margin  basic_earnings_per_share  \\\n",
       "0             7.236100e+10           0.341462                      9.72   \n",
       "1             7.273800e+10           0.366863                      9.70   \n",
       "2             6.127100e+10           0.364517                      8.12   \n",
       "3             4.428100e+10           0.309625                      5.82   \n",
       "4             3.924000e+10           0.311817                      5.11   \n",
       "\n",
       "   diluted_earnings_per_share  weighted_average_basic_shares_outstanding  \\\n",
       "0                        9.68                               7.446000e+09   \n",
       "1                        9.65                               7.496000e+09   \n",
       "2                        8.05                               7.547000e+09   \n",
       "3                        5.76                               7.610000e+09   \n",
       "4                        5.06                               7.673000e+09   \n",
       "\n",
       "   weighted_average_diluted_shares_outstanding  \\\n",
       "0                                 7.472000e+09   \n",
       "1                                 7.540000e+09   \n",
       "2                                 7.608000e+09   \n",
       "3                                 7.683000e+09   \n",
       "4                                 7.753000e+09   \n",
       "\n",
       "                                                link  \\\n",
       "0  https://www.sec.gov/Archives/edgar/data/789019...   \n",
       "1  https://www.sec.gov/Archives/edgar/data/789019...   \n",
       "2  https://www.sec.gov/Archives/edgar/data/789019...   \n",
       "3  https://www.sec.gov/Archives/edgar/data/789019...   \n",
       "4  https://www.sec.gov/Archives/edgar/data/789019...   \n",
       "\n",
       "                                          final_link  \n",
       "0  https://www.sec.gov/Archives/edgar/data/789019...  \n",
       "1  https://www.sec.gov/Archives/edgar/data/789019...  \n",
       "2  https://www.sec.gov/Archives/edgar/data/789019...  \n",
       "3  https://www.sec.gov/Archives/edgar/data/789019...  \n",
       "4  https://www.sec.gov/Archives/edgar/data/789019...  \n",
       "\n",
       "[5 rows x 36 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# For example, if we only wanted our agent to use the `.equity.fundamental.income` tool:\n",
    "from openbb import obb\n",
    "obb.equity.fundamental.income(\"MSFT\").to_df()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-06-03 10:48:35,316 - INFO - openbb_agents.agent - Using specified OpenBB tools: ['.equity.fundamental.income']\n",
      "2024-06-03 10:48:36,362 - INFO - openbb_agents.agent - Generating subquestions for user query: What is the most recent annual revenue of MSFT?\n",
      "2024-06-03 10:48:37,613 - INFO - openbb_agents.agent - Generated subquestions: [SubQuestion(id=1, question='What is the most recent annual revenue of MSFT?', depends_on=None)]\n",
      "2024-06-03 10:48:37,614 - INFO - openbb_agents.agent - Answering subquestion: id=1 question='What is the most recent annual revenue of MSFT?' depends_on=None\n",
      "2024-06-03 10:48:37,614 - INFO - openbb_agents.agent - Attempting to select tools for: {'What is the most recent annual revenue of MSFT?'}\n",
      "2024-06-03 10:48:38,482 - INFO - openbb_agents.chains - Searching tool index for: annual revenue\n",
      "2024-06-03 10:48:40,143 - INFO - openbb_agents.agent - Retrieved tool(s): ['income']\n",
      "2024-06-03 10:48:40,144 - INFO - openbb_agents.agent - Answering subquestion: What is the most recent annual revenue of MSFT?\n",
      "2024-06-03 10:48:41,236 - INFO - openbb_agents.chains - Function call: income({'symbol': 'MSFT', 'period': 'annual', 'limit': 1})\n",
      "2024-06-03 10:48:44,584 - INFO - openbb_agents.agent - Answered subquestion: - The most recent annual revenue of Microsoft Corporation (MSFT) is $211.915 billion.\n",
      "- This data is for the fiscal year ending on June 30, 2023.\n",
      "- The information was filed on July 27, 2023.\n",
      "\n",
      "For further details, you can refer to the [SEC filing](https://www.sec.gov/Archives/edgar/data/789019/000095017023035122/msft-20230630.htm).\n",
      "- The most recent annual revenue of Microsoft Corporation (MSFT) is $211.915 billion.\n",
      "- This data is for the fiscal year ending on June 30, 2023.\n",
      "- The information was filed on July 27, 2023.\n",
      "- For further details, you can refer to the [SEC filing](https://www.sec.gov/Archives/edgar/data/789019/000095017023035122/msft-20230630.htm).\n"
     ]
    }
   ],
   "source": [
    "#... then we can specify it using the `openbb_tools` input argument\n",
    "result = openbb_agent(\"What is the most recent annual revenue of MSFT?\", openbb_tools=[\".equity.fundamental.income\"])\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using custom tools\n",
    "You're also not limited to OpenBB's suite of tools. If you have custom tools you'd like to specify and add to the tool index (so that the LLM can search for your tool while c ompleting tasks), you can do so simply by adding a custom tool to the agent.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-06-03 10:48:55,133 - INFO - openbb_agents.agent - Using all available OpenBB tools with providers: ['yfinance', 'fmp']\n",
      "2024-06-03 10:48:55,134 - INFO - openbb_agents.tools - Building OpenBB tool vector index...\n",
      "2024-06-03 10:49:08,001 - INFO - openbb_agents.tools - Adding user-specified tools to vector index...\n",
      "2024-06-03 10:49:08,332 - INFO - openbb_agents.agent - Generating subquestions for user query: What is the weather at AMZN's headquarters?\n",
      "2024-06-03 10:49:09,879 - INFO - openbb_agents.agent - Generated subquestions: [SubQuestion(id=1, question=\"Where is AMZN's headquarters located?\", depends_on=None), SubQuestion(id=2, question=\"What is the current weather at the location of AMZN's headquarters?\", depends_on=[1])]\n",
      "2024-06-03 10:49:09,880 - INFO - openbb_agents.agent - Answering subquestion: id=1 question=\"Where is AMZN's headquarters located?\" depends_on=None\n",
      "2024-06-03 10:49:09,880 - INFO - openbb_agents.agent - Attempting to select tools for: {\"Where is AMZN's headquarters located?\"}\n",
      "2024-06-03 10:49:10,988 - INFO - openbb_agents.chains - Searching tool index for: headquarters location\n",
      "2024-06-03 10:49:13,988 - INFO - openbb_agents.agent - Retrieved tool(s): ['management', 'insider_trading']\n",
      "2024-06-03 10:49:13,988 - INFO - openbb_agents.agent - Answering subquestion: Where is AMZN's headquarters located?\n",
      "2024-06-03 10:49:15,122 - INFO - openbb_agents.chains - Function call: management({'symbol': 'AMZN'})\n",
      "2024-06-03 10:49:18,132 - INFO - openbb_agents.agent - Answered subquestion: - Amazon's headquarters is located in Seattle, Washington, USA.\n",
      "\n",
      "This information is inferred from the fact that Amazon's key executives, including the CEO and other senior management, are typically based at the company's headquarters.\n",
      "2024-06-03 10:49:18,133 - INFO - openbb_agents.agent - Answering subquestion: id=2 question=\"What is the current weather at the location of AMZN's headquarters?\" depends_on=[1]\n",
      "2024-06-03 10:49:18,134 - INFO - openbb_agents.agent - Attempting to select tools for: {\"What is the current weather at the location of AMZN's headquarters?\"}\n",
      "2024-06-03 10:49:18,950 - INFO - openbb_agents.chains - Searching tool index for: current weather\n",
      "2024-06-03 10:49:22,639 - INFO - openbb_agents.agent - Retrieved tool(s): ['get_weather']\n",
      "2024-06-03 10:49:22,640 - INFO - openbb_agents.agent - Answering subquestion: What is the current weather at the location of AMZN's headquarters?\n",
      "2024-06-03 10:49:23,844 - INFO - openbb_agents.chains - Function call: get_weather({'location': 'Seattle, Washington, USA'})\n",
      "2024-06-03 10:49:24,986 - INFO - openbb_agents.agent - Answered subquestion: - The current weather at Amazon's headquarters in Seattle, Washington, USA is approximately 12.75°C.\n",
      "- Amazon's headquarters is located in Seattle, Washington, USA.\n",
      "- The current weather at Amazon's headquarters in Seattle, Washington, USA is approximately 12.75°C.\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "def get_weather(location: str) -> float:\n",
    "    \"\"\"Get the weather for a given location, in degress Celsius.\"\"\"\n",
    "    return random.uniform(0, 50)\n",
    "\n",
    "# We can make extra tools available to the agent using the `extra_tools` input argument\n",
    "result = openbb_agent(\"What is the weather at AMZN's headquarters?\", extra_tools=[get_weather])\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Async agent\n",
    "An `async` agent is also available for use in your asnychronous workflows. This can lead to speed-ups in certain situations (we're still improving this over time!)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-06-03 10:49:38,971 - INFO - openbb_agents.agent - Using all available OpenBB tools with providers: ['yfinance', 'fmp']\n",
      "2024-06-03 10:49:38,972 - INFO - openbb_agents.tools - Building OpenBB tool vector index...\n",
      "2024-06-03 10:49:53,849 - INFO - openbb_agents.agent - Pending subquestions: [SubQuestion(id=1, question='What is the current stock price of AAPL?', depends_on=[]), SubQuestion(id=2, question='What is the current stock price of MSFT?', depends_on=[])]\n",
      "2024-06-03 10:49:53,850 - INFO - openbb_agents.agent - Answerable subquestions: [SubQuestion(id=1, question='What is the current stock price of AAPL?', depends_on=[]), SubQuestion(id=2, question='What is the current stock price of MSFT?', depends_on=[])]\n",
      "2024-06-03 10:49:53,850 - INFO - openbb_agents.agent - Scheduling subquestion for answer: id=1 question='What is the current stock price of AAPL?' depends_on=[]\n",
      "2024-06-03 10:49:53,851 - INFO - openbb_agents.agent - Scheduling subquestion for answer: id=2 question='What is the current stock price of MSFT?' depends_on=[]\n",
      "2024-06-03 10:49:53,851 - INFO - openbb_agents.agent - Attempting to select tools for: {'What is the current stock price of AAPL?'}\n",
      "2024-06-03 10:49:53,882 - INFO - openbb_agents.agent - Attempting to select tools for: {'What is the current stock price of MSFT?'}\n",
      "2024-06-03 10:49:54,611 - INFO - openbb_agents.chains - Searching tool index for: stock price\n",
      "2024-06-03 10:49:55,014 - INFO - openbb_agents.chains - Searching tool index for: stock price\n",
      "2024-06-03 10:49:57,255 - INFO - openbb_agents.agent - Retrieved tool(s): ['quote', 'historical']\n",
      "2024-06-03 10:49:57,257 - INFO - openbb_agents.agent - Answering subquestion: What is the current stock price of MSFT?\n",
      "2024-06-03 10:49:57,497 - INFO - openbb_agents.agent - Retrieved tool(s): ['quote', 'historical']\n",
      "2024-06-03 10:49:57,497 - INFO - openbb_agents.agent - Answering subquestion: What is the current stock price of AAPL?\n",
      "2024-06-03 10:49:58,119 - INFO - openbb_agents.chains - Function call: quote({'symbol': 'MSFT'})\n",
      "2024-06-03 10:49:59,085 - INFO - openbb_agents.chains - Function call: quote({'symbol': 'AAPL'})\n",
      "2024-06-03 10:50:03,820 - INFO - openbb_agents.agent - Answered subquestion: - The current stock price of Apple Inc. (AAPL) is $192.25.\n",
      "- This data was last updated on May 31, 2024, at 20:00:03 UTC.\n",
      "- The stock opened at $191.44, reached a high of $192.57, and a low of $189.91 on the same day.\n",
      "- The previous closing price was $191.29.\n",
      "- The trading volume for the day was 74,776,921 shares.\n",
      "- The 52-week high for AAPL is $199.62, and the 52-week low is $164.08.\n",
      "- The average trading volume over the last 50 days is 62,563,592 shares.\n",
      "- The market capitalization of Apple Inc. is approximately $2.95 trillion.\n",
      "2024-06-03 10:50:03,822 - INFO - openbb_agents.agent - Finished task for subquestion: subquestion=SubQuestion(id=1, question='What is the current stock price of AAPL?', depends_on=[]) answer='- The current stock price of Apple Inc. (AAPL) is $192.25.\\n- This data was last updated on May 31, 2024, at 20:00:03 UTC.\\n- The stock opened at $191.44, reached a high of $192.57, and a low of $189.91 on the same day.\\n- The previous closing price was $191.29.\\n- The trading volume for the day was 74,776,921 shares.\\n- The 52-week high for AAPL is $199.62, and the 52-week low is $164.08.\\n- The average trading volume over the last 50 days is 62,563,592 shares.\\n- The market capitalization of Apple Inc. is approximately $2.95 trillion.'\n",
      "2024-06-03 10:50:03,823 - INFO - openbb_agents.agent - Pending subquestions: [SubQuestion(id=2, question='What is the current stock price of MSFT?', depends_on=[])]\n",
      "2024-06-03 10:50:03,824 - INFO - openbb_agents.agent - Answerable subquestions: [SubQuestion(id=2, question='What is the current stock price of MSFT?', depends_on=[])]\n",
      "2024-06-03 10:50:03,824 - INFO - openbb_agents.agent - Scheduling subquestion for answer: id=2 question='What is the current stock price of MSFT?' depends_on=[]\n",
      "2024-06-03 10:50:05,793 - INFO - openbb_agents.agent - Answered subquestion: - The current stock price of Microsoft Corporation (MSFT) is $415.13.\n",
      "- This data was last updated on May 31, 2024, at 20:00:02 UTC.\n",
      "\n",
      "Relevant retrieved data:\n",
      "- **Symbol**: MSFT\n",
      "- **Last Price**: $415.13\n",
      "- **Open**: $416.41\n",
      "- **High**: $416.63\n",
      "- **Low**: $404.52\n",
      "- **Volume**: 47,676,297\n",
      "- **Previous Close**: $414.67\n",
      "- **Change**: $0.46\n",
      "- **Change Percent**: 0.11%\n",
      "- **Year High**: $433.60\n",
      "- **Year Low**: $309.45\n",
      "- **50-Day Average Price**: $416.448\n",
      "- **200-Day Average Price**: $378.9645\n",
      "- **Market Cap**: $3,085,374,850,300\n",
      "- **Shares Outstanding**: 7,432,310,000\n",
      "- **EPS**: $11.54\n",
      "- **PE Ratio**: 35.97\n",
      "- **Next Earnings Announcement**: July 23, 2024, at 10:59 UTC\n",
      "2024-06-03 10:50:05,793 - INFO - openbb_agents.agent - Finished task for subquestion: subquestion=SubQuestion(id=2, question='What is the current stock price of MSFT?', depends_on=[]) answer='- The current stock price of Microsoft Corporation (MSFT) is $415.13.\\n- This data was last updated on May 31, 2024, at 20:00:02 UTC.\\n\\nRelevant retrieved data:\\n- **Symbol**: MSFT\\n- **Last Price**: $415.13\\n- **Open**: $416.41\\n- **High**: $416.63\\n- **Low**: $404.52\\n- **Volume**: 47,676,297\\n- **Previous Close**: $414.67\\n- **Change**: $0.46\\n- **Change Percent**: 0.11%\\n- **Year High**: $433.60\\n- **Year Low**: $309.45\\n- **50-Day Average Price**: $416.448\\n- **200-Day Average Price**: $378.9645\\n- **Market Cap**: $3,085,374,850,300\\n- **Shares Outstanding**: 7,432,310,000\\n- **EPS**: $11.54\\n- **PE Ratio**: 35.97\\n- **Next Earnings Announcement**: July 23, 2024, at 10:59 UTC'\n",
      "2024-06-03 10:50:05,794 - INFO - openbb_agents.agent - Pending subquestions: []\n",
      "2024-06-03 10:50:05,794 - INFO - openbb_agents.agent - Answerable subquestions: []\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'- The current stock price of Apple Inc. (AAPL) is $192.25.\\n- The current stock price of Microsoft Corporation (MSFT) is $415.13.'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from openbb_agents.agent import aopenbb_agent\n",
    "\n",
    "await aopenbb_agent(\"What is the stock price of AAPL and MSFT?\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "obb-agents",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
